package online.foxnull2.foxmall.seckill.web;

import online.foxnull2.foxmall.seckill.service.SeckillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class SeckillWebController {

    private final SeckillService seckillService;

    @Autowired
    public SeckillWebController(SeckillService seckillService) {
        this.seckillService = seckillService;
    }

    //http://seckill.foxmall.com/seckill?seckillId=4_31&code=19317798fd964148a1b4fa607eb62682&num=1
    @GetMapping("/seckill")
    public String seckill(@RequestParam("seckillId") String seckillId,
                          @RequestParam("code") String code,
                          @RequestParam("num") Integer num,
                          Model model) {
        String orderSn = seckillService.seckill(seckillId, code, num);
        model.addAttribute("orderSn", orderSn);
        return "success";
    }
}
